﻿function escape2(str)
{
	return escape(str).replace(/\+/g,"%2b");
}
function getWindowSize() 
{//得到ie窗口大小
	var e = new Object(); 
	if(window.self && self.innerWidth) 
	{ 
		e.width = self.innerWidth; 
		e.height = self.innerHeight; 
	} 
	else if(document.documentElement && document.documentElement.clientHeight) 
	{ 
		e.width = document.documentElement.clientWidth; 
		e.height = document.documentElement.clientHeight; 
	}else 
	{ 
		e.width = document.body.clientWidth; 
		e.height = document.body.clientHeight; 
	} 
	return e 
} 
function focusinput(o,bkey)
{//文本框得到热点
    if(o.value == bkey)
    {
        o.value= "";        
        o.style.color="#000000";
    }
    o.style.backgroundColor = "#F0F8FF";
}
function blurinput(o,bkey)
{//文本框失去热点
    if(o.value.trim() == "")
    {       
        o.style.color="#cccccc";
        o.value = bkey;
    }
    o.style.backgroundColor = "";
}

var aXmlHttp = new Array();
var aXmlResponse = new Array();
function xmlResult()
{
    for(var i=0;i<aXmlHttp.length;i++)
    {
        if(aXmlHttp[i] && aXmlHttp[i][0] && aXmlHttp[i][0].readyState==4&&aXmlHttp[i][0].responseText)
        {
            var f = aXmlHttp[i][2];
            var o = aXmlHttp[i][1];
            var s = aXmlHttp[i][0].responseText;
            aXmlHttp[i][0] = null;
            aXmlHttp[i][1] = null;
            aXmlHttp[i] = null;
            f.apply(o,new Array(s));
        }
    }
}
// u -> url
// o -> object (can be null) to invoke function on
// f -> callback function
// p -> optional argument to specify POST
function call(u,o,f)
{//XmlHttp Ajax 异步回调 参数[URL，执行者，回调执行的方法]
    var method = "GET";
    var dat;
    if (arguments.length==4)
    {
        method = "POST";
        tmp = u.split(/\?/);
        u   = tmp[0];
        dat = tmp[1];
    }
    var idx = aXmlHttp.length;
    for(var i=0; i<idx;i++)
    if (aXmlHttp[i] == null)
    {
        idx = i;
        break;
    }
    aXmlHttp[idx]=new Array(2);
    aXmlHttp[idx][0] = getXmlHttp();

    aXmlHttp[idx][1] = o;
    aXmlHttp[idx][2] = f;
    if(aXmlHttp[idx])
    {
       aXmlHttp[idx][0].open(method,u,true);
       if(method == "POST")
       {
          aXmlHttp[idx][0].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          aXmlHttp[idx][0].send(dat);
       }
       aXmlHttp[idx][0].onreadystatechange=xmlResult;        
       if(method =="GET")
       {
          aXmlHttp[idx][0].send(null);
       }
    }
}
function getXmlHttp()
{//创建XMLHTTP对象
    var A=null;
    if(!A && typeof XMLHttpRequest != "undefined")
    {
        A=new XMLHttpRequest();
    }
    if (!A)
    {
        try
        {
            A=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                A=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(oc)
            {
                A=null
            }
        }
    }    
    return A;
}
var backupuserbar = "";
function userlogin()
{
    var tbxuser = $("username");
    var tbxpass = $("userpwd");
    var username = tbxuser.value.trim();
    var userpwd = tbxpass.value;
    if(username == "")
    {
        alert('请输入用户名！');
        tbxuser.focus();
        return;
    }
   if(userpwd == "")
    {
        alert('请输入密码！');
        tbxpass.focus();
        return;
    }
    var option={
		parameters:"oper=login&state=1&name="+username+"&pass="+userpwd+"&time="+Date(),
		method:"get",
		onSuccess:function(transport)
		{
			var rp=transport.responseText;
			if(rp=="ok")
			{ 
			    window.location.href="mapindex.aspx";
			}
			else if(rp=="noname") 
			{ 
			    alert("用户名错误！"); 
			}
			else if(rp=="nopass") 
			{
			    alert("密码错误，请重新输入！");
			}
			else if(rp=="noaudit") 
			{
			    alert("对不起，您的帐号被禁用！");
			}
			else if(rp=="nologin") 
			{
			    alert("对不起，您的帐号被禁用！");
			}
			else if(rp = "notallowrole")
			{
			    alert("对不起，你所在的用户组没有权限使用！");
			}
			else
			{
			    var pnl = $("pnllogin");			    
			    pnl.innerHTML = rp;
			    return;
			}
			var pnl = $("pnllogin");
			pnl.innerHTML = backupuserbar;
		},
		onFailure:function(transport)
		{
			alert(transport.responseText+"数据提交失败，请检查网络或重试。");
		}
	}
	var pnl = $("pnllogin");
	backupuserbar = pnl.innerHTML;
	pnl.innerHTML = "<font color=red>正在登录......</font>";
	//window.open("ajax.aspx?" + option.parameters);
	var request=new Ajax.Request("ajax.aspx",option);
	return;
}
function userlogout()
{
    var option={
		parameters:"oper=login&state=-1"+"&time="+Date(),
		method:"get",
		onSuccess:function(transport)
		{
			var rp=transport.responseText;
		    var pnl = $("pnllogin");
		    pnl.innerHTML = rp;
		},
		onFailure:function(transport)
		{
		}
	}
	//window.open("ajax.aspx?" + option.parameters);
	var request=new Ajax.Request("ajax.aspx",option);
	return;
}
function myaccount()
{
    frame.src="userinfo.htm";
}
function keylogin(e)
{
    e = (e)?e:((event)?event:null);
    if(e)
    {    
        var charCode=(e.charCode)?e.charCode:e.keyCode;
        if(charCode == 13)
        {
			userlogin();
		}
	}
}

function go(url)
{
    var tbx = document.getElementsByName("pagenum");
    for(var i=0;i<tbx.length;i++)
    {
        tbxpage = tbx[i];        
        if(tbxpage && tbxpage.value != "")
        {
            window.location=url.replace("{page}",tbxpage.value);
            return ;
        }        
    }
    alert('请输入跳转的页码!');
}

function viewWebmap(lon,lat,tp,id,title)
{
	window.open("webmap/worldmap.aspx?tp="+tp+"&x="+lon+"&y="+lat+"&title="+title+"&id=" +id);
}
function FlexViewWebmap(lon, lat, id, tp) {
   // alert(lon+","+lat+","+id+","+tp);
    if (lon != "" && lat != "") {
        if (lat == "0" && lon == "0") {
            alert("无当前点坐标!");
        }
        else {
            window.open("webmap/flex/WorldMapFlex.aspx?id=" + id + "&tp=" + tp);
        }
    }
    else {
        alert("无当前点坐标!");
    }
} 
function viewGoogleEarth(tp,id)
{
	var dlLocation = 'GEView.aspx?tp='+tp+'&id=' + id;
	self.location.href = dlLocation;
}
function viewGoogleMaps(lon,lat,tp,id,title)
{
	window.open("webmap/Gmaps2.aspx?tp="+tp+"&x="+lon+"&y="+lat+"&title="+title+"&id=" +id);
}
